package com.tengfei.main.meituan;

import java.util.Scanner;

/**
 * @author feige
 * @version v1.0
 * @date 2022-11-21-20:45
 * @description
 */
public class Qu4 {

    static int maxScore = 0;
    static int len = 0;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        len = sc.nextInt();
        int[] arr = new int[len];
        for (int i = 0; i < len; i++) {
            arr[i] = sc.nextInt();
        }
        sc.close();
        toMax(arr, 0, 0, 1);
        System.out.println(maxScore);

    }

    private static void toMax(int[] arr, int idx, int score, int buff) {
        if (idx == len) {
            if (score > maxScore)
                maxScore = score;
            return;
        }
        if (arr[idx] == 0) {
            score += buff;
            toMax(arr, ++idx, score, buff);
        } else {

            // 使用
            toMax(arr, ++idx, (score / 2), ++buff);
            buff--;
            // 丢弃
            toMax(arr, ++idx, (score + buff), buff);
        }
    }
}
